package com.nextbus.ui;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.nextbus.main.R;

/**
 * @author dxt
 *
 */
public class BalloonoverLayView <Item extends OverlayItem> extends FrameLayout{
	
	protected LinearLayout layout;
	private TextView title;
	private TextView snippet;
	protected View layoutView;
	protected float density;
	private Context context;
	
	public BalloonoverLayView(Context context, int balloonBottomOffset,float density) {
		super(context);
		
		this.context=context;
		this.density = density;
		setPadding(10, 0, 10, balloonBottomOffset);
		layout = new LinearLayout(context);
		layout.setVisibility(VISIBLE);

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layoutView = inflater.inflate(R.layout.balloon_map_overlay, layout);
		
		title = (TextView) layoutView.findViewById(R.id.balloon_item_title);
		snippet = (TextView) layoutView.findViewById(R.id.balloon_item_snippet);

	}
	
	
	/**
	 * dxt
	 * 把busoverlayitem里面的数据     传递到框图的两个变量中
	 * 
	 * @param item - The overlay item containing the relevant view data 
	 * (title and snippet). 
	 */
	public void setData(Item item) {    
		if (item!=null) {
			layout.setVisibility(VISIBLE);
			if (item.getTitle() != null) {
				title.setVisibility(VISIBLE);
				title.setText(Html.fromHtml(item.getTitle()));
			} else {
				title.setVisibility(GONE);
			}
			if (item.getSnippet() != null) {
				snippet.setVisibility(VISIBLE);
				snippet.setText(Html.fromHtml(item.getSnippet()));
			} else {
				snippet.setVisibility(GONE);
			}
		}else {
			Toast.makeText(context, "当前点击的不是图标", Toast.LENGTH_LONG);
		}
		

	}
}
